<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body id="bd">
  <input type="button" value="关灯" id="btn">
  <script>
    var btn = document.getElementById("btn");
    var bd = document.querySelector("body");
    // var bd = document.getElementsByTagName("body");
    // bd.style.backgroundColor = "red"
    // console.log(bd);
    btn.onclick = function () {
      if (btn.value === "关灯") {
        bd.style.backgroundColor = "black"
        btn.value = "开灯"
      }else {
        bd.style.backgroundColor = "white"
        btn.value = "关灯"
      }
    }
  </script>
</body>
</html>